package net.maku.member.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.common.utils.Result;
import net.maku.framework.security.user.SecurityUser;
import net.maku.framework.security.user.UserDetail;
import net.maku.member.convert.MemberUserConvert;
import net.maku.member.entity.MemberUserEntity;
import net.maku.member.service.MemberUserService;
import net.maku.member.query.MemberUserQuery;
import net.maku.member.vo.MemberUserTransferVO;
import net.maku.member.vo.MemberUserVO;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;

import java.util.List;

/**
 * 会员信息
 *
 * @author 阿沐 babamu@126.com
 * @since 1.0.0 2025-03-15
 */
@RestController
@RequestMapping("/member/user")
@Tag(name = "会员信息")
@AllArgsConstructor
public class MemberUserController {
    private final MemberUserService memberUserService;

    @GetMapping("getDetail/{id}")
    @Operation(summary = "信息")
    public Result<MemberUserVO> get(@PathVariable("id") Long id) {

        return Result.ok(memberUserService.getInfo(id));
    }

    @GetMapping("getLoginMemberInfo")
    @Operation(summary = "信息")
    public Result<MemberUserVO> getLoginMemberInfo(){
        UserDetail user = SecurityUser.getUser();
        Long id = user.getId();
        return Result.ok(memberUserService.getInfo(id));
    }

    @PostMapping
    @Operation(summary = "保存")
    public Result<String> save(@RequestBody MemberUserVO vo) {
        memberUserService.save(vo);

        return Result.ok();
    }

    @PutMapping
    @Operation(summary = "修改")
    public Result<String> update(@RequestBody @Valid MemberUserVO vo) {
        memberUserService.update(vo);

        return Result.ok();
    }


}